<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="entity.ProductBean" %>
<%@ page import="entity.PageBean" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Bootstrap 布局实例</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/list.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/user.js"></script>
</head>

<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12" id="right">
            <ol class="breadcrumb">
                <li class="active">菜单
                </li>
                <li class="active">产品信息
                </li>
            </ol>
            <%
                request.setCharacterEncoding("UTF-8");
                String productCode = "";
                String productName = "";
                String batch = "";
                String worker = "";
                String workshop = "";

                //从ProductListServlet中获取值
                if (request.getAttribute("productCode") != null) productCode = (String) request.getAttribute("productCode");
                if (request.getAttribute("productName") != null) productName = (String) request.getAttribute("productName");
                if (request.getAttribute("batch") != null) batch = (String) request.getAttribute("batch");
                if (request.getAttribute("worker") != null) worker = (String) request.getAttribute("worker");
                if (request.getAttribute("workshop") != null) workshop = (String) request.getAttribute("workshop");

                //分页
                PageBean pageBean = (PageBean) request.getAttribute("pageBean");
                int curPage = pageBean.getCurPage();
                int pageCount = pageBean.getPageCount();
                int pageNumStart = pageBean.getStartPage();
                int pageNumEnd = pageBean.getEndPage();
            %>
            <div class="panel panel-default">
                <div class="panel-heading">
                    搜索
                </div>
                <div class="panel-body">
                    <form role="form" class="form-inline" action="ProductListServlet" method="post">
                        <div class="form-group">
                            <label>产品身份码</label>
                            <input type="text" class="form-control custom-smaller-input" id="productCode"
                                   name="productCode" value="<%=productCode%>" placeholder="请输入产品身份码">
                        </div>
                        <div class="form-group">
                            <label>产品名称</label>
                            <input type="text" class="form-control custom-smaller-input" id="productName" name="productName"
                                   value="<%=productName%>" placeholder="请输入产品名称">
                        </div>
                        <div class="form-group">
                            <label>批次</label>
                            <input type="text" class="form-control custom-smaller-input" id="batch"
                                   name="batch" placeholder="请输入加工批次"
                                   value="<%=batch%>">
                        </div>
                        <div class="form-group">
                            <label>加工人员</label>
                            <input type="text" class="form-control custom-smaller-input" id="worker"
                                   name="worker"
                                   value="<%=worker%>" placeholder="请输入加工人员名称">
                        </div>
                        <div class="form-group">
                            <label>加工车间</label>
                            <select class="form-control" id="workshop" name="workshop">
                                <option value="">请选择加工车间</option>
                                <option value="表面处理车间" <% if (workshop.equals("表面处理车间"))
                                    out.print("selected"); %> >
                                    表面处理车间
                                </option>
                                <option value="锻压车间" <% if (workshop.equals("锻压车间"))
                                    out.print("selected"); %> >
                                    锻压车间
                                </option>
                                <option value="组装车间" <% if (workshop.equals("组装车间"))
                                    out.print("selected"); %> >
                                    组装车间
                                </option>
                                <option value="质检车间" <% if (workshop.equals("质检车间"))
                                    out.print("selected"); %> >
                                    质检车间
                                </option>
                                <option value="机加车间" <% if (workshop.equals("机加车间"))
                                    out.print("selected"); %> >
                                    机加车间
                                </option>
                            </select>
                        </div>
                        <div class="form-group">
                            <button type="submit" class="searchButton btn btn-primary">搜索</button>
                        </div>
                        <div class="form-group">
                            <a class="addButton btn btn-default" href="ProductEditServlet?type=add">添加</a>
                        </div>
                    </form>
                </div>
            </div>
            <!--
            列表展示
        -->
            <div class="table-responsive">
                <table class="table table-striped ">
                    <thead>
                    <tr>
                        <%--<th>序号</th>--%>
                        <th>产品身份码</th>
                        <th>产品名称</th>
                        <th>外观尺寸</th>
                        <th>批次</th>
                        <th>加工人员</th>
                        <th>加工方法</th>
                        <th>加工时间</th>
                        <th>加工车间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <%
                        List<ProductBean> productList = (List<ProductBean>) request.getAttribute("productList");
                        if (productList != null) {
                            for (ProductBean obj : productList) {
                    %>
                    <tr>
                        <td><%=obj.getProductCode()%>
                        </td>
                        <td><%=obj.getProductName()%>
                        </td>
                        <td><%=obj.getProductSize()%>
                        </td>
                        <td><%=obj.getBatch()%>
                        </td>
                        <td><%=obj.getWorker()%>
                        </td>
                        <td><%=obj.getProcessingMethod()%>
                        </td>
                        <td><%=obj.getProcessingDate()%>
                        </td>
                        <td><%=obj.getWorkshop()%>
                        </td>
                        <td>
                            <div class="btn-group">
                                <a class="reviseButton btn btn-default" href="ProductEditServlet?type=mod&id=<%=obj.getId()%>">修改</a>
                                <a class="deleteButton btn btn-danger"
                                   href="#" onclick="confirmDelete(<%=obj.getId()%>)">删除</a>
                            </div>
                        </td>
                    </tr>
                    <%
                            } // for
                        } // if (productList != null)
                    %>
                    </tbody>
                </table>
            </div>
            <ul class="pagination" style="float: right;">
                <li><span style="pointer-events: none">共<%=pageCount%>页</span></li>
                <li>
                    <a href="ProductListServlet?alterpage=-1&page=<%=curPage%>&productCode=<%=productCode%>&productName=<%=productName%>&workshop=<%=workshop%>&worker=<%=worker%>&batch=<%=batch%>">&laquo;</a>
                </li>
                <%
                    for (int i = pageNumStart ; i <= pageNumEnd; i++) {
                        if (i == curPage) {
                            out.println("<li class=\"active\"><a href=\"ProductListServlet?page=" + i + "&productCode=" + productCode + "&productName=" + productName + "&workshop=" + workshop + "&worker=" + worker + "&batch=" + batch + "\">" + i + "</a></li>");

                        } else {
                            out.println("<li><a href=\"ProductListServlet?page=" + i + "&productCode=" + productCode + "&productName=" + productName + "&workshop=" + workshop + "&worker=" + worker + "&batch=" + batch + "\">" + i + "</a></li>");
                        }
                    }
                %>
                <li>
                    <a href="ProductListServlet?alterpage=1&&page=<%=curPage%>&productCode=<%=productCode%>&productName=<%=productName%>&workshop=<%=workshop%>&worker=<%=worker%>&batch=<%=batch%>">&raquo;</a>
                </li>
            </ul>
        </div>
    </div>
</div>

</body>
<script>
    function confirmDelete(id) {
        if (confirm("确定要删除吗？")) {
            window.location.href = "ProductEditServlet?type=del&id="+id+"&page=<%=curPage%>&productCode=<%=productCode%>&productName=<%=productName%>&workshop=<%=workshop%>&worker=<%=worker%>&batch=<%=batch%>";
        }
    }
</script>
</html>